#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 100001;
struct A
{
	int w, v, id;
} a[N];

int n, vol, tr[N];

bool compare(A x, A y)
{
	if (x.w < y.w) return true;
	if (x.w == y.w && x.v < y.v) return true;
	return false;
}

int main()
{
	scanf("%d%d", &n, &vol);
	for (int i = 0; i != n; ++i) {
		scanf("%d%d", &a[i].w, &a[i].v);
		a[i].id = i + 1;
	}
	sort(a, a + n, compare);
	int pos = n-1;
	for (int i = 0; i != n; ++i)
		if (a[i].w == 2) {
			pos = i-1; break;
		}
	int ans = 0, len = 0, p = pos;
	if (vol & 1) {
		if (pos >= 0) {
			tr[len++] = a[pos].id;
			ans += a[pos--].v;
		}
		--vol;
	}
	--n;
	while (vol > 0 && (pos >= 0 || n > p)) {
		int tmp = 0;
		if (pos >= 0) tmp = a[pos].v;
		if (pos-1 >= 0) tmp += a[pos-1].v;
		if (n > p) {
			if (a[n].v > tmp) {
				ans += a[n].v;
				tr[len++] = a[n--].id;
			} else {
				ans += tmp;
				tr[len++] = a[pos--].id;
				if (pos >= 0) tr[len++] = a[pos--].id;
			}
		} else {
			ans += tmp;
			tr[len++] = a[pos--].id;
			if (pos >= 0) tr[len++] = a[pos--].id;
		}
		vol -= 2;
	}
	printf("%d\n", ans);
	for (int i = 0; i != len; ++i) printf("%d ", tr[i]);
}
